var post_idd  = sessionStorage.getItem("postnow");
function postconment(){
    var usserr_id = sessionStorage.getItem("user");
    var commentvalue = document.getElementById("comment-input").value;
    if(commentvalue == ''){
        Qmsg.info('评论内容不能为空');
        return false;
    }
    if(!confirm('您确定要发布评论吗？')){
        return false;
    }
    if(usserr_id === null){
       Qmsg.error('请先登录');
       setTimeout(function(){
           location.href = '/center-person/lgreg.php';
       },1000);
        return false;
    }
    fetch('book/comment.php?userid='+usserr_id+'&plnr='+commentvalue+'&postid='+post_idd, {
  method: 'GET', 
  headers: {
    'Content-Type': 'application/json', 
  },
})
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.json(); 
})
.then(function (data) {
            if (data.type === 'success') {
                alert(data.message);
            } else {
                alert(data.message);
            }
        })
.catch((error) => {
  console.error('There has been a problem with your fetch operation:', error);
});
}
window.addEventListener('load', function() {
    var commentsList = document.getElementById('comments-list');
    commentsList.style.maxHeight = '300px';
    commentsList.style.overflowY = 'auto';
    commentsList.style.overflowX = 'hidden'; 
});